<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
class Register extends Controller
{
    //注册用户
    public function getregister()
    {
    	// echo '1111';exit;
        return $this->fetch("Register/register");
    }
    //检测邮箱
    public function getcheckemail(){
        //请求对象
        $request = request();
        $email = $request->get("email");
        // echo $email;exit;
        //做邮箱对比
        $arr = Db::table("member")->column("email");
        // echo $arr;exit;
        if(in_array($email,$arr)){
            echo '1';
        }else{
            echo '0';
        }
    }
    //检测号码
    public function getchecktel(){
        //请求对象
        $request = request();
        $tel = $request->get("tel");
        //做手机号码对比
        $arr = Db::table("member")->column("tel");
        if(in_array($tel,$arr)){
            echo '1';
        }else{
            echo '0';
        }
    }
    //获取校验码
    public function getcheckp(){
        //请求对象
        $request = request();
        $tel = $request->get("tel");
        // echo $tel;exit;
        //调用云之讯,发送短信验证码
        sends($tel);
    }
    //检测校验码是否合法
    public function getcheckcode(){
        //请求对象
        $request = request();
        //获取校验的校验码
        $code = $request->get("code");
        //对比校验码
        if(isset($_COOKIE['vcode']) && !empty($code)){
            //获取手机接收到的校验码
            $vcode = $_COOKIE['vcode'];
            //对比
            if($code!==$vcode){
                echo 0;
            }else{
                echo 1;
            }
        }else{
            echo 2;
        }
    }
    //执行注册
    public function postdoregister(){
        //创建请求
        $request = request();
        //获取注册信息
        // $token = rand(1000,9999);
        $data=$request->only(['tel','password','email']);
        // $data['token'] = $token;
        if(Db::table('member')->insert($data)){
            $this->success("注册成功","/homelogin/login");
        }else{
            $this->error("注册失败","/homeregister/register");
        }
    }

    
}
